package cn.edu.zut.curriculum.controller;

import cn.edu.zut.curriculum.entity.Commodity;
import cn.edu.zut.curriculum.entity.Order;
import cn.edu.zut.curriculum.entity.User;
import cn.edu.zut.curriculum.service.ICommodityService;
import cn.edu.zut.curriculum.service.IOrderSerivice;
import cn.edu.zut.curriculum.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class OrderController {
    @Autowired
    IOrderSerivice iOrderSerivice;
    @Autowired
    IUserService iUserService;
    @Autowired
    ICommodityService iCommodityService;
    @GetMapping("/commodityList")     //接收闲置物品超链接跳转
    public ModelAndView select(ModelAndView mav, @RequestParam("uid") long uid)throws NullPointerException{
       // System.out.println("uid="+uid);
        List<Order> list=iOrderSerivice.select(uid);
        User user=iUserService.select(uid);
        Commodity commodity;

            List<Commodity> list1=new ArrayList<>();
            for (Order order : list) {
                long cid = order.getCid();
                System.out.println("cid=" + cid);
                commodity = iCommodityService.select2(cid);
                System.out.println(commodity);
                list1.add(commodity);
            }
             mav.addObject("list", list1);
             mav.addObject("user", user);
             mav.setViewName("User/commodityList");
             return mav;
    }
}
